/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package decisionTree;

import java.io.FileNotFoundException;
import java.util.ArrayList;

/**
 *
 * @author hubert
 */
public class top100List extends topXList {

    private java.util.ArrayList<stringWeightPair> wordWeightList;

    public top100List(java.io.File src) {
        this.wordWeightList = new java.util.ArrayList<stringWeightPair>();
        
        try {
            java.util.Scanner reader = new java.util.Scanner(src);
            String cur = "";
            while (reader.hasNextLine()) {
                cur = reader.nextLine();
                //System.out.println(cur);
                String[] cur2 = cur.split(",");
                //System.out.println(cur2[0]);
                
                this.wordWeightList.add(new decisionTree.stringWeightPair(cur2[0], Double.parseDouble(cur2[1])));
                
                
            }
        } catch (java.io.FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    public int indexOf(String in){
        int serve = -1;
        for(int i = 0; i < this.wordWeightList.size(); i++){
            if(this.wordWeightList.get(i).string.compareTo(in) == 0){
                serve = i;
                break;
            }
        }
        return serve;
    }
    
    public String toString(){
        java.lang.StringBuilder serve = new java.lang.StringBuilder();
        for(stringWeightPair en: this.wordWeightList){
            serve.append(en.string + "\t" + en.weight +"\n");
        }
        return serve.toString();
    }
    
    public top100List(){
        this(new java.io.File("./top100ByZScore"));
        this.wordWeightList = new java.util.ArrayList<stringWeightPair>();
    }

    public void saveToFile(java.io.File targ){
        try{
            java.io.PrintWriter out = new java.io.PrintWriter(targ);
            out.write(this.toString());
            out.flush();
            out.close();
        }
        catch(java.io.FileNotFoundException e){
            e.printStackTrace();
        }
    }
    
    public top100List(java.io.File src, String delimiter) {
        this.wordWeightList = new java.util.ArrayList<stringWeightPair>();
        
        try {
            java.util.Scanner reader = new java.util.Scanner(src);
            String cur = "";
            while (reader.hasNextLine()) {
                cur = reader.nextLine();
                //System.out.println(cur);
                String[] cur2 = cur.split(delimiter);
                //System.out.println(cur2[0]);
                
                this.wordWeightList.add(new decisionTree.stringWeightPair(cur2[0], Double.parseDouble(cur2[1])));
                
                
            }
        } catch (java.io.FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    
    public top100List entryByEntyWeightMult(top100List en){
        top100List serve = new top100List();
        for(int i = 0; i < this.wordWeightList.size(); i++){
            serve.wordWeightList.add(new stringWeightPair(this.wordWeightList.get(i).string,this.wordWeightList.get(i).weight*en.wordWeightList.get(i).weight));
        }
        return serve;
    }
    
    @Override
    public ArrayList<stringWeightPair> getWordWeightList() {
        return this.wordWeightList;
    }
}
